const errorHandler = (err, req, res, next) => {
  console.error(err.stack);
  
  const statusCode = res.statusCode !== 200 ? res.statusCode : 500;
  res.status(statusCode).json({
    error: {
      message: err.message || '服务器内部错误',
      code: err.code || 'INTERNAL_SERVER_ERROR'
    }
  });
};

module.exports = errorHandler;  